﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;

namespace DYSales.Views
{
    public partial class cwin_class : ChildWindow
    {
        public cwin_class()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(cwin_class_Loaded);
            bt_打印.Click += new RoutedEventHandler(bt_打印_Click);
        }

        void bt_打印_Click(object sender, RoutedEventArgs e)
        {
            dm.getDS().GetSetTable(lo =>
            {
                if (!lo.HasError)
                {
                    PrintManager.tbs = new List<TextBlock>();
                    PrintManager.tbcount = 0;
                    var setting = lo.Value;
                    TextBlock tb = PrintManager.CreatePrintTextBlock(setting.s_打印页宽);
                    tb.Inlines.Add(new Run() { FontSize = setting.s_字体大小 + 1, FontWeight = FontWeights.Bold, Text = setting.s_店名 + "交班结算单" });
                    tb.Inlines.Add(new LineBreak());
                    tb.Inlines.Add(new Run() { FontSize = setting.s_字体大小, Text = "营业总金额：" + tbk_营业总金额.Text });
                    tb.Inlines.Add(new LineBreak());
                    tb.Inlines.Add(new Run() { FontSize = setting.s_字体大小, Text = "现金支付总金额：" + tbk_现金支付总金额.Text });
                    tb.Inlines.Add(new LineBreak());
                    tb.Inlines.Add(new Run() { FontSize = setting.s_字体大小, Text = "刷卡支付总金额：" + tbk_刷卡支付总金额.Text });
                    tb.Inlines.Add(new LineBreak());
                    tb.Inlines.Add(new Run() { FontSize = setting.s_字体大小, Text = "交班时间：" + tbk_交班时间.Text });
                    tb.Inlines.Add(new LineBreak());
                    tb.Inlines.Add(new Run() { FontSize = setting.s_字体大小, Text = "统计范围：" + tbk_统计范围.Text });
                    tb.Inlines.Add(new LineBreak());
                    tb.Inlines.Add(new Run() { FontSize = setting.s_字体大小, Text = "操作员：" + tbk_操作员.Text});
                    tb.Inlines.Add(new LineBreak());
                    PrintManager.tbs.Add(tb);
                    PrintManager.GetPrintManager().DoPrint();
                }
            }, null);
        }

        void cwin_class_Loaded(object sender, RoutedEventArgs e)
        {
            dm.getDS().GetST(lt =>
            {
                dm.getDS().GetSetTable(ls =>
                {
                    var lttime = lt.Value;
                    var lstime = ls.Value.s_营业开始时间;
                    var lstime2 = ls.Value.s_营业结束时间;
                    var start = new DateTime(lttime.Year, lttime.Month, lttime.Day, lstime.Hour, lstime.Minute, lstime.Second);
                    var end = new DateTime(lttime.Year, lttime.Month, lttime.Day, lstime2.Hour, lstime2.Minute, lstime2.Second).AddDays(1);
                    dm.getDS().GetTotalClassByTime(WebContext.Current.User.Name, start, end, lo =>
                    {
                        g_统计.DataContext = lo.Value;
                    }, null);
                }, null);
            }, null);
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}

